<style lang="less">
</style>
<template>
    <div class="search">
        <Row>
            <Col>
                <Card>
                        <Row>
                            <Form ref="searchForm" :model="searchForm" inline :label-width="160" class="search-form">
                                <Row class="operation">
                                    <i-col span="8">
                                        <Form-item label="合作商名称" prop="channelFullName">
                                            <Input type="text" v-model="searchForm.channelFullName" clearable placeholder="请输入合作商名称"
                                                   style="width: 200px"/>
                                        </Form-item>
                                    </i-col>
                                </Row>
                                <Row  style="text-align: center">
                                    <Form-item style="margin-left:-60px; text-align: center" class="br">
                                        <Button @click="handleSearch" type="primary" icon="ios-search">查询</Button>
                                        <Button @click="handleReset" icon="md-redo">重置</Button>
                                    </Form-item>
                                </Row>
                            </Form>
                        </Row>
                    <Row>
                        <Table :loading="loading" border :columns="columns" :data="data" sortable="custom"
                               @on-sort-change="changeSort" @on-selection-change="showSelect" ref="table">
                            <template slot-scope="{ row, index }" slot="action">
                                <Button style="margin-right:5px" type="primary" size="small" @click="edit(row)">我要办理</Button>
                            </template>
                            <template slot-scope="{ row, index }" slot="businessType">
                                <span>{{setBusinessTypeTitle(row.businessType)}}</span>
                            </template>

                            <template slot-scope="{ row, index }" slot="userName">
                                <span>{{setUserNameTitle()}}</span>
                            </template>
                        </Table>
                    </Row>

                    <Row type="flex" justify="end" class="page">
                        <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize"
                              @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]"
                              size="small" show-total show-elevator show-sizer></Page>
                    </Row>
                    </Card>
            </Col>
        </Row>
    </div>
</template>
<script>
    import {
        getChannelOnlineWorkFlowData,
    } from "@/projects/afs-channel/api/workflow/workflow";
    import {getDictDataByType} from "_p/basic/api/admin/datadic";

    import {
        getAllRegionalManager
    } from "_p/afs-channel/api/common/common.js"

    export default {
        name: "channelManage",
        components: {
        },
        data() {
            return {
                loading: true,
                operationLoading: false,
                loadingExport: true,
                drop: false,
                dropDownContent: "更多",
                dropDownIcon: "ios-arrow-down",
                selectCount: 0,
                selectList: [],
                bizDataId:"",
                userNameList:[],
                searchForm: {
                    pageNumber: 1,
                    pageSize: 10,
                },
                //业务类型字典处理
                businessTypeList:[],
                selectDate: null,
                columns: [
                    {
                        type: 'index',
                        title:"序号",
                        minWidth: 80,
                        align: "center",
                        fixed: "left"

                    },
                    {
                        title: "合作商名称",
                        key: "channelFullName",
                        minWidth: 150,
                        align: "center",
                        fixed: "left",
                    },
                    {
                        title: "任务名称",
                        key: "taskName",
                        align: "center",
                        minWidth: 145
                    },
                    {
                        title: "处理人",
                        key: "userName",
                        align: "center",
                        minWidth: 150,
                        slot:"userName"
                    },
                    {
                        title: "处理人名称",
                        key: "userRealName",
                        align: "center",
                        minWidth: 150
                    },
                    {
                        title: "业务类型",
                        key: "businessType",
                        minWidth: 100,
                        align: "center",
                        slot:"businessType"
                    },
                    {
                        title: "流程启动时间",
                        key: "createTime",
                        align: "center",
                        minWidth: 70
                    },
                    {
                        title: "操作",
                        key: "action",
                        minWidth: 70,
                        align: "center",
                        fixed: "right",
                        slot: "action"
                    }
                ],
                data: [],
                total: 0
            };
        },
        methods: {
            init() {
                this.getChannelOnlineWorkFlow();
                this.initLabelType();
            },
            changePage(v) {
                this.searchForm.pageNumber = v;
                this.getChannelOnlineWorkFlow();
                this.clearSelectAll();
            },
            changePageSize(v) {
                this.searchForm.pageSize = v;
                this.getChannelOnlineWorkFlow();
            },
            selectDateRange(v) {
                if (v) {
                    this.searchForm.startDate = v[0];
                    this.searchForm.endDate = v[1];
                }
            },
            getChannelOnlineWorkFlow() {
                // 多条件搜索渠道列表
                this.loading = true;
                getChannelOnlineWorkFlowData(this.searchForm).then(res => {
                    this.loading = false;
                    if (res.code === "0000") {
                        if(res.data.records[0].userName !=null && res.data.records[0].userName !="" && res.data.records[0].userName !=undefined){
                            getAllRegionalManager(res.data.records[0].userName).then(res => {
                                if (res.code === "0000") {
                                    this.userNameList = [];
                                    res.data.data.forEach((item, i) => {
                                        this.userNameList.push(item.userRealName)
                                    })
                                }
                            });
                        }
                        this.data = res.data.records;
                        this.total = res.data.total;
                    }
                });
            },

            handleSearch() {
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.getChannelOnlineWorkFlow();
            },
            handleReset() {
                this.$refs.searchForm.resetFields();
                this.searchForm.pageNumber = 1;
                this.searchForm.pageSize = 10;
                this.selectDate = null;
                this.searchForm.startDate = "";
                this.searchForm.endDate = "";
                this.searchForm.authFegion = "";
                // 重新加载数据
                this.getChannelOnlineWorkFlow();
            },
            changeSort(e) {
                this.searchForm.sort = e.key;
                this.searchForm.order = e.order;
                if (e.order === "normal") {
                    this.searchForm.order = "";
                }
                this.getChannelOnlineWorkFlow();
            },

            edit(v) {
                let param={
                    //按钮是否隐藏：保存、提交、返回展示，黑名单隐藏
                    bottonView:0,
                    //信息是否只读:1 非只读
                    infoView:1,
                    //操作类型：1，修改
                    operationType:1,
                    //渠道id
                    channelId:v.id,
                    channelType:v.channelBelong,
                    channelStatus:v.channelStatus,
                    channelStatusOldCar:v.channelStatusOldCar,
                    businessType:v.businessType,
                    bizDataId:v.bizDataId,
                    channelDeposit:v.channelDeposit,
                    channelDepositPaidIn:v.channelDepositPaidIn
                };
                this.channelModalVisible = false;
                this.afs.newTab(this,'projects/afs-channel/pages/dealer-apply/dealer-approve/approveDetail','渠道审核','ios-add',param,"channelOnlineApprove-approve"+v.id,[],true)
            },
            dropDown() {
                if (this.drop) {
                    this.dropDownContent = "更多";
                    this.dropDownIcon = "ios-arrow-down";
                } else {
                    this.dropDownContent = "收起";
                    this.dropDownIcon = "ios-arrow-up";
                }
                this.drop = !this.drop;
            },
            showSelect(e) {
                this.selectList = e;
                this.selectCount = e.length;
            },
            clearSelectAll() {
                this.$refs.table.selectAll(false);
            },
            //业务类型处理
            setBusinessTypeTitle(val){
                if(val==null ||val=="" ||val ==undefined){
                    return;
                }
                let dic = {};
                let valTemp = val.split(',');
                if(valTemp.length>1){
                    let title ="";
                    for(let i in valTemp ){
                        this.businessTypeList.forEach(column => {
                            if(column.value === valTemp[i]){
                                dic = column;
                                title =title+"  "+dic.title;
                            }
                        });
                    }
                    return title
                }else{
                    let dic = {};
                    this.businessTypeList.forEach(column => {
                        if(column.value === val){
                            dic = column;
                        }
                    });
                    return dic.title;
                }
            },

            //处理人翻译
            setUserNameTitle(){
                let title="";
                this.userNameList.forEach((item, i) => {
                    title = item + " " + title;
                })
                return title;
            },

            initLabelType(){
                let businessTypeDic="businessType";
                getDictDataByType(businessTypeDic).then(res =>{
                    if (res.code === "0000"){
                        this.businessTypeList = res.data;
                    }
                });
            }

        },
        created() {},
        mounted() {
            this.init();
        },
        watch: {
            '$route'(to,from){
                this.handleReset();
            }
        },
    };
</script>
<style scoped>
</style>
